package com.wz.utils.concurrency.concurrenthashmap;

import java.util.HashMap;
import java.util.Iterator;


public class ExceptionTest {

    public static void main(String[] args) {
        HashMap<String, String> hashMap = new HashMap<>();  //对象.modCount

        hashMap.put("1", "1");   // 1
        hashMap.put("2", "2");   // 2

        Iterator i$ = hashMap.keySet().iterator();   // KeyIterator  2  expectedModCount=2

        // fast-fail
        while(i$.hasNext()) {
            String key = (String)i$.next();   //
            if (key.equals("2")) {
                i$.remove(); // modcount++
            }
        }





        // t1  reve


        // t2 xunhu
//        Iterator<String> iterator = hashMap.keySet().iterator();  // KeyIterator--->HashIterator     expectedModCount=2
//        while (iterator.hasNext()) {
//            String key = iterator.next();   // HashIterator.nextEntry().getKey()
//            if (key.equals("2")) {
//                iterator.remove(key); // modcount=3
//            }
//        }



    }

}
